using System;
using System.Text;
using System.Collections.Generic;
using System.Reflection;



namespace Open.Data.Persistence
{
    public class Conditions : List<Condition>
    {
        public Conditions(): base()
        {
            Operator = ConditionsOperator.And;
        }

        public ConditionsOperator Operator { get; set; }

        public Comparison AddComparison(Expression expression, Expression compareTo)
        {
            Comparison comparison = new Comparison(expression, compareTo);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, Expression compareTo)
        {
            Comparison comparison = new Comparison(column, compareTo);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, Expression compareTo, ComparisonOperator op)
        {
            Comparison comparison = new Comparison(expression, compareTo, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, Expression compareTo, ComparisonOperator op)
        {
            Comparison comparison = new Comparison(column, compareTo, op);
            Add(comparison);
            return comparison;
        }

        public Comparison AddComparison(Expression expression, string value)
        {
            StringParameter parm = new StringParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, string value, ComparisonOperator op)
        {
            StringParameter parm = new StringParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, string value)
        {
            StringParameter parm = new StringParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, string value, ComparisonOperator op)
        {
            StringParameter parm = new StringParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }

        public Comparison AddComparison(Expression expression, long value)
        {
            LongParameter parm = new LongParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, long value, ComparisonOperator op)
        {
            LongParameter parm = new LongParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, long value)
        {
            LongParameter parm = new LongParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, long value, ComparisonOperator op)
        {
            LongParameter parm = new LongParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, int value)
        {
            IntegerParameter parm = new IntegerParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, int value, ComparisonOperator op)
        {
            IntegerParameter parm = new IntegerParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, int value)
        {
            IntegerParameter parm = new IntegerParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, int value, ComparisonOperator op)
        {
            IntegerParameter parm = new IntegerParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, DateTime value)
        {
            DateTimeParameter parm = new DateTimeParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, DateTime value, ComparisonOperator op)
        {
            DateTimeParameter parm = new DateTimeParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, DateTime value)
        {
            DateTimeParameter parm = new DateTimeParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, DateTime value, ComparisonOperator op)
        {
            DateTimeParameter parm = new DateTimeParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, bool value)
        {
            BooleanParameter parm = new BooleanParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, bool value, ComparisonOperator op)
        {
            BooleanParameter parm = new BooleanParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, bool value)
        {
            BooleanParameter parm = new BooleanParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, bool value, ComparisonOperator op)
        {
            BooleanParameter parm = new BooleanParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, short value)
        {
            ShortParameter parm = new ShortParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, short value, ComparisonOperator op)
        {
            ShortParameter parm = new ShortParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, short value)
        {
            ShortParameter parm = new ShortParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, short value, ComparisonOperator op)
        {
            ShortParameter parm = new ShortParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, double value)
        {
            DoubleParameter parm = new DoubleParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, double value, ComparisonOperator op)
        {
            DoubleParameter parm = new DoubleParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, double value)
        {
            DoubleParameter parm = new DoubleParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, double value, ComparisonOperator op)
        {
            DoubleParameter parm = new DoubleParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, float value)
        {
            FloatParameter parm = new FloatParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, float value, ComparisonOperator op)
        {
            FloatParameter parm = new FloatParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, float value)
        {
            FloatParameter parm = new FloatParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, float value, ComparisonOperator op)
        {
            FloatParameter parm = new FloatParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, decimal value)
        {
            DecimalParameter parm = new DecimalParameter(value);
            Comparison comparison = new Comparison(expression, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Expression expression, decimal value, ComparisonOperator op)
        {
            DecimalParameter parm = new DecimalParameter(value);
            Comparison comparison = new Comparison(expression, parm, op);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, decimal value)
        {
            DecimalParameter parm = new DecimalParameter(value);
            Comparison comparison = new Comparison(column, parm);
            Add(comparison);
            return comparison;
        }
        public Comparison AddComparison(Column column, decimal value, ComparisonOperator op)
        {
            DecimalParameter parm = new DecimalParameter(value);
            Comparison comparison = new Comparison(column, parm, op);
            Add(comparison);
            return comparison;
        }

        public virtual void AppendHashCode(StringBuilder builder)
        {
            foreach (Condition condition in this)
            {
                condition.AppendHashCode(builder);

                //Append sub conditions
                if (condition.SubConditions != null) condition.SubConditions.AppendHashCode(builder);
            }
        }
    }
}

